<?php

namespace App\Models;


class GoodsComment extends Base
{

    // 用户管理
    protected $table = 'goods_cate';

    // 缓存字段，用于搜索绑定的字段
    protected $cacheFields = ['id'];

    // 获取图片
    protected function getImgsAttr($value)
    {
        $images = json_decode($value, true);
        if(empty($images)){
            return [];
        }

        $res = [];
        foreach($images as $img){
            $res[] = $this->replaceDomain($img, 'full');
        }

        return $res;
    }

    // 保存图片
    protected function setImgsAttr($value)
    {
        if(is_string($value)){
            $value = json_decode($value, true);
        }

        $res = [];
        foreach($value as $img){
            $res[] = $this->replaceDomain($img, 'old');
        }

        return json_encode($res);
    }


    // 获取图片
    protected function getPicAttr($value)
    {
        return $this->replaceDomain($value, 'full');
    }

    // 保存图片
    protected function setPicAttr($value)
    {
        return $this->replaceDomain($value, 'old');
    }


    // 获取图片
    protected function getContentAttr($value)
    {
        return $this->replaceDomain($value, 'full');
    }

    // 保存图片
    protected function setContentAttr($value)
    {
        return $this->replaceDomain($value, 'old');
    }


    // 定义验证操作
    public function rules()
    {

        $add = [
        ];

        $edit = [
        ];

        $info = [
        ];


        $rule = [
            'ip'   => 'required',
            'city' => 'required',
            'prov' => 'required',
        ];


        $msg = [
            'id'       => '',
            'uid'      => '用户',
            'order_id' => '订单id',
            'goods_id' => '商品id',
            'images'   => '评论图片',
            'comment'  => '评论',
            'ctime'    => '创建时间',
            'mtime'    => '修改时间',
        ];

        return ['rule' => $rule, 'msg' => $msg, 'add' => $add];
    }
}
